package main

import (
	"fmt"
	"runtime"
	"task/client"
	"task/config"
	"time"
)

/*
loading config
*/
func init() {
	fmt.Println("loading", "start run")
	config.Register()
	client.Register()
}

func test() {
	for i := 0; i < 100; i++ {
		go testfor()
		time.Sleep(10 * time.Second)
		fmt.Println("test", i)
	}

}

func testfor() {
	for {
		// fmt.Println("---for----")
	}
}

func main() {
	if msgs, err := client.MQ.RecvMessage(config.Conf.SusuanImageMatchRecognition, false, 10); err == nil {
		for msg := range msgs {
			fmt.Println(fmt.Sprintf("%s", string(msg.Body)), "Receive msg", "system")
			defer deferfunc()
			go testfor()
			msg.Ack(false)
		}
	}
}

func deferfunc() {
	if err := recover(); err != nil {
		const size = 64 << 10
		buf := make([]byte, size)
		buf = buf[:runtime.Stack(buf, false)]
		fmt.Println("system", "deferfunc", fmt.Sprintf("err:%s\nstack:%s", err, string(buf)))
	}
}
